<?php
/**
 * *数据转换文件操作*
 */
define('IN_APP', 1); // 定义 IN_APP ,表示是正常入口进入. 后面的文件里都定义了见不到 IN_APP 就 die
define('GROUP_NAME','')   ;
error_reporting(~E_ALL);
define('OOAPP_DIRNAME', 'web_admin');
define('OO_JUMP', 1); // 定义了这个 那么就可以跳过 thinkphp 直接执行到后面代码,而不用管什么控制器

// thinkphp 的设置和加载
define('APP_DEBUG', true);

define('APP_NAME', ''); // 定义项目名称
define('WWW_PATH', str_replace("\\", '/', dirname(__FILE__))); //当前项目路径
define('APP_PATH', dirname(dirname(__FILE__)) . '/' . OOAPP_DIRNAME . '/'); //定义项目路径

//define('MODE_NAME','cli'); // 设置为命令模式
$_set = dirname(__FILE__).'/ind/js/set.php';   // $_GINFO 设置在 set.php 中
if(file_exists($_set)) require $_set;
// define('MODE_NAME','cli'); // 设置为命令模式
require dirname(dirname(__FILE__)) . '/' . OOAPP_DIRNAME . '/INC.php'; // INC.php 框架模型必须具备的类,不管什么项目都需要加载

require dirname(dirname(__FILE__)) . '/ThinkPHP/ThinkPHP.php';

set_time_limit(0); // 不限制执行时间


$dbselect = Db::G3();

$start  = getReq($argv,1,date("Y-m-d",time()));
$end    = getReq($argv,2,date("Y-m-d",time()));
$j=0;
for($i = strtotime($start); $i <= strtotime($end); $i += 86400) {
    $curday =date("Y-m-d",$i);
    $startdate  = $curday." 00:00:00";
    $enddate    = $curday." 23:59:59";

    $y=date("Y",strtotime($curday));
    $m=date("m",strtotime($curday));
    $d=date("d",strtotime($curday));


    $repaywhere      = "";
    if($startdate!="" && $enddate!=""){
      $repaywhere    = " and repay_yestime>='$startdate' and  repay_yestime<='$enddate'";  
    }
    //当日还清标 分站
    $rows = $dbselect->GetRows("SELECT r.cid,r.repay_yestime AS '还款时间',COUNT(r.id) AS '次数', SUM(r.repay_capital) AS '本金'
    FROM 05b_2list_repay r LEFT JOIN `05b_0base` b ON r.`bid`=b.`bid`
    WHERE  ((r.`repay_period`=-1 AND b.borrow_style IN (1,3,4)) OR  (r.`repay_period`=b.`borrow_period` AND b.borrow_style NOT IN (1,3,4))) $repaywhere
    GROUP BY r.cid, repay_yestime  ");
    foreach($rows as &$row)
    { 
        $cid    = $row['cid'];
        $ctime  = $row['还款时间'];
        $r_c    = $row['本金'];
        $count  = $row['次数']; 
        if($count>0){
            CTLog::G()->pxxDayReal($count.",cid",$cid,'借款人_还清标',$r_c,$ctime);
        }
    }
    //当日还清标 总站
    $rows = $dbselect->GetRows("SELECT r.cid,r.repay_yestime AS '还款时间',COUNT(r.id) AS '次数', SUM(r.repay_capital) AS '本金'
    FROM 05b_2list_repay r LEFT JOIN `05b_0base` b ON r.`bid`=b.`bid`
    WHERE  ((r.`repay_period`=-1 AND b.borrow_style IN (1,3,4)) OR  (r.`repay_period`=b.`borrow_period` AND b.borrow_style NOT IN (1,3,4))) $repaywhere
    GROUP BY repay_yestime  ");
    foreach($rows as &$row)
    { 
        $ctime  = $row['还款时间'];
        $r_c    = $row['本金'];
        $count  = $row['次数']; 
        if($count>0){
            CTLog::G()->pxxDayReal($count.",sid",1,'借款人_还清标',$r_c,$ctime);
        }
    }
    echo "$curday 完成\r\n";
}   

